<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style type="text/css">
    .col-xs-1-5,
    .col-sm-1-5,
    .col-md-1-5,
    .col-lg-1-5 {
        position: relative;
        min-height: 1px;
        padding-right: 10px;
        padding-left: 10px;
    }

    .col-xs-1-5 {
        width: 20%;
        float: left;
    }

    @media (min-width: 768px) {
        .col-sm-1-5 {
            width: 20%;
            float: left;
        }
    }

    @media (min-width: 992px) {
        .col-md-1-5 {
            width: 20%;
            float: left;
        }
    }

    @media (min-width: 1200px) {
        .col-lg-1-5 {
            width: 20%;
            float: left;
        }
    }
</style>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>下达设计任务</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="code" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="name" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <form id="taskForm" style="display: none">
        <div class="row">
            <div class="col-md-1-5">
                <div class="box box-warning box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">挤压装备设计所</h3>
                    </div>
                    <div class="box-body" style="display: block; height: 160px">
                        <div class="form-group" th:each="section : ${pid11}">
                            <label class="checkbox-inline icheck">
                                <input type="checkbox" name="sectionId" class="minimal-red" th:value="${section.id}"
                                       th:text="${section.name}">
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-1-5">
                <div class="box box-warning box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">熔铸装备设计所</h3>
                    </div>
                    <div class="box-body" style="display: block; height: 160px">
                        <div class="form-group" th:each="section : ${pid12}">
                            <label class="checkbox-inline icheck">
                                <input type="checkbox" name="sectionId" class="minimal-red" th:value="${section.id}"
                                       th:text="${section.name}">
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-1-5">
                <div class="box box-warning box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">深加工装备设计所</h3>
                    </div>
                    <div class="box-body" style="display: block; height: 160px">
                        <div class="form-group" th:each="section : ${pid14}">
                            <label class="checkbox-inline icheck">
                                <input type="checkbox" name="sectionId" class="minimal-red" th:value="${section.id}"
                                       th:text="${section.name}">
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-1-5">
                <div class="box box-warning box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">流体传动设计所</h3>
                    </div>
                    <div class="box-body" style="display: block; height: 160px">
                        <div class="form-group" th:each="section : ${pid15}">
                            <label class="checkbox-inline icheck">
                                <input type="checkbox" name="sectionId" class="minimal-red" th:value="${section.id}"
                                       th:text="${section.name}">
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-1-5">
                <div class="box box-warning box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">自动化与智能控制设计所</h3>
                    </div>
                    <div class="box-body" style="display: block; height: 160px">
                        <div class="form-group" th:each="section : ${pid13}">
                            <label class="checkbox-inline icheck">
                                <input type="checkbox" name="sectionId" class="minimal-red" th:value="${section.id}"
                                       th:text="${section.name}">
                            </label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <input id="projectId" type="hidden" name="projectId">
        <button shiro:hasPermission="dsn:task:config" type="button" id="btn_task" class="btn btn-info btn-success pull-right">
            下达设计任务
        </button>
    </form>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;

    // 配置
    function config(id) {
        js.reset("taskForm", false);
        $("#projectId").val(id);
        $("#taskForm").show();
    }

    $(function () {

        /** 待下达设计任务列表 */
        table = js.table.init({
            url: ctx + "designTask/add/taskList",
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'code'},
                {title: "项目名称", field: 'name', width: '260px'},
                {title: "项目数量", field: 'num'},
                {title: "需方", field: 'demander'},
                {title: "安装地点", field: 'address'},
                {title: "备注", field: 'comment'},
                {
                    title: "操作",
                    formatter: function (value, row) {
                        let actions = [];
                        if (hasP('dsn:task:config')) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="config(' + row.id + ')"> 分配任务</a>');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /** 下达任务 */
        $("#btn_task").click(function () {
            if ($("input[name='sectionId']:checked").length === 0) {
                js.modal.warning("至少选择一个科室下发任务！O(∩_∩)O~ ！");
                return;
            }
            js.post({
                url: ctx + "designTask/add/distribute",
                data: $("#taskForm").serialize(),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.reset("taskForm", false);
                        $("#taskForm").hide();
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });

    });
</script>
</body>
</html>
